// pages/class/classes.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: ""
  },

  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    console.log(e)
    var app = getApp();
    var testUrl = app.testUrl;
    var that = this;
    wx.request({
      url: testUrl + '/lesson/search.do?page=1&rows=50',
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        title: e.detail.value
      },
      success: function (res) {
        console.log(res)
        that.setData({
          inputVal: e.detail.value,
          searchList: res.data.rows
        });
      }
    })
  },


  toClassList:function(event){
    wx.navigateTo({
      url: '/pages/classList/classlist?id=' + parseInt(event.currentTarget.dataset.categoryid),
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var app = getApp();
    if (app.globalData.openid == null) {
      app.getset()
    }


    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var app=getApp();
    var testUrl=app.testUrl;
    var that=this;
    //获取推荐课程

    wx.request({
      url: testUrl + '/lesson/search.do?page=1&rows=50',
      method:"POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
         recommend: 1
      
      },
    
      success: function (res) {
        that.setData({
          lessonList: res.data.rows
        });
        console.log(res.data)
      }
    })

    //获取轮播图
    wx.request({
      url: testUrl + '/trollImg/findAll.do',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        that.setData({
          trollImgList: res.data
        });
      
      }
    });
    //获取课程分类
    wx.request({
      url: testUrl + '/lessonCategory/findAll.do',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        that.setData({
          lessonCategoryList: res.data
        });
    
      }
    });
  },

 

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  toDetail: function () {
    wx.navigateTo({
      url: '/pages/video/video',
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  toDetail: function (event) {
    wx.navigateTo({
      url: '/pages/video/video?classid=' + parseInt(event.currentTarget.dataset.classid),
    })
  },

  troltoDetail: function (event) {
    wx.navigateTo({
      url: '/pages/video/video?classid=' + parseInt(event.currentTarget.dataset.troclassid),
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})